/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.oai.metadataRepository.analysis.impl;

import cz.mzk.oai.metadataRepository.analysis.Analysis;
import cz.mzk.oai.metadataRepository.analysis.EnhanceResultOperation;
import cz.mzk.oai.metadataRepository.metadata.MetadataFormat;
import java.util.HashMap;
import java.util.Map;
import org.dom4j.DocumentHelper;
import org.dom4j.XPath;

/**
 *
 * @author Martin Řehánek (rehan at mzk.cz)
 */
public class MarcDatafieldAnalysis implements Analysis {

    private final int datafield;
    private final char subfield;

    public MarcDatafieldAnalysis(int datafield, char subfield) {
        this.datafield = datafield;
        this.subfield = subfield;

    }

    public MetadataFormat getMetadataFormat() {
        return MetadataFormat.marc21;
    }

    public EnhanceResultOperation getOperation() {
        //return new HandInResultOperation();
        return new ClassifyLinksOperation();
    }

    public XPath getXpath() {
        Map<String, String> prefixNamespaceMap = new HashMap<String, String>();
        prefixNamespaceMap.put("marc21", "http://www.loc.gov/MARC21/slim");
        XPath elementXpath = DocumentHelper.createXPath("/marc21:record/marc21:datafield[@tag='" + datafield + "']/marc21:subfield[@code='" + subfield + "']");
        elementXpath.setNamespaceURIs(prefixNamespaceMap);
        return elementXpath;
    }
}
